package com.woniuxy.joylifeshop.controller;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.common.entity.ShopMerchantCurrentAccount;
import com.woniuxy.joylifeshop.service.MerchantCurrentAccountService;
import com.woniuxy.joylifeshop.vo.ViewObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
public class MerchantCurrentAccountController {

    @Autowired
    MerchantCurrentAccountService merchantCurrentAccountService;

    /**
    * @Author SooYoo
    * @Description 查询商家流水
    * @Param 
    * @Return 
    **/
    @RequestMapping("/readCurrent")
    public ViewObject readCurrent (@RequestBody HashMap<String,String> information) {
        //从json中获取数据
        String jsonstr = information.get("jsonstr");
        ShopMerchantCurrentAccount ShopMerchantCurrentAccount = JSON.parseObject(jsonstr, ShopMerchantCurrentAccount.class);
        //封装VO
        ViewObject viewObject = new ViewObject();
        //分页
        PageHelper.startPage(Integer.parseInt(information.get("page")),Integer.parseInt(information.get("limit")));
        //找到需要的流水对象
        List<ShopMerchantCurrentAccount> shopMerchantCurrentAccounts = merchantCurrentAccountService.readCurrentObjectByCondition(ShopMerchantCurrentAccount);
        //分页2
        PageInfo pageInfo = new PageInfo(shopMerchantCurrentAccounts);
        List<PageInfo> pageInfos = new ArrayList<>();
        pageInfos.add(pageInfo);
        //配置vo
        viewObject.setData(pageInfos);
        viewObject.setCode(0);
        viewObject.setCount(new Long(pageInfo.getTotal()).intValue());
        viewObject.setMsg("查询成功");
        return viewObject ;
    }


}
